package com.fbs.controller;

import com.aaa.entity.EmpInfo;
import com.aaa.entity.Role;
import com.aaa.vo.EmpInfoVo;
import com.aaa.vo.Result;
import com.fbs.dao.EERoleDao;
import com.fbs.dao.EmpInfoDao;
import com.fbs.service.EmpInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.events.Event;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@Api("/emp")
@RestController
@RequestMapping("/emp")
@EnableSwagger2
public class EmpInfoController {
    @Autowired
    private EmpInfoService empInfoService;
    @Autowired
    private EERoleDao eeRoleDao;
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EmpInfo", name = "empInfo", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageNum", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("/findAll")
    public Result findAll(@RequestBody EmpInfo empInfo, Integer pageNum, Integer pageSize){
        return empInfoService.findAll(empInfo.getEname(), pageNum,pageSize);
    }
    @ApiOperation(value = "", notes = "")
    @RequestMapping("roleAll")
    public Result roleAll(){
        List<Role> roles = eeRoleDao.selectList(null);
        return new Result(200,"查询成功",roles);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EmpInfo", name = "empInfo", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("insert")
    public Result insert(@RequestBody EmpInfo empInfo){
        return empInfoService.insert(empInfo);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("delete/{id}")
    public Result delete(@PathVariable Integer id){
        return empInfoService.delete(id);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EmpInfo", name = "empInfo", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("save")
    public Result save(@RequestBody EmpInfo empInfo){
        return empInfoService.save(empInfo);
    }
}
